﻿using System.Collections.Generic;
using BIS.Portal.Modules.CMS.Entity;


namespace BIS.Portal.Modules.CMS.Adm
{
    public class AdminListViewUtility
    {
        /// <summary>
        /// Parses the list.
        /// </summary>
        /// <param name="parentid">The parentid.</param>
        /// <param name="children">The children.</param>
        /// <param name="list">The list.</param>
        public static void ParseList(int parentid, ref IList<AdminCmsCategoryEntity> children, ref IList<AdminCmsCategoryEntity> list)
        {
            for (int i = 0; i < children.Count; i++)
            {
                if (children[i].Parent_category_id == parentid)
                {
                    list.Add(children[i]);

                    ParseList(children[i].Category_id, ref children, ref list);
                }
            }

        }

        /// <summary>
        /// Adds the dot list.
        /// </summary>
        /// <param name="listAdmin">The list admin.</param>
        public static void AddDotList(ref IList<AdminCmsCategoryEntity> listAdmin)
        {
            int dot = 0;
            for (int i = 1; i < listAdmin.Count; i++)
            {
                if (listAdmin[i].Parent_category_id == 0)
                {
                    dot = 0;
                }
                else
                {
                    if (listAdmin[i].Parent_category_id == listAdmin[i - 1].Category_id)
                    {
                        dot++;
                    }
                    else if (dot > 1 && i > 1 && listAdmin[i].Parent_category_id != listAdmin[i - 1].Parent_category_id)
                    {
                        dot--;
                    }

                    // add dot to category name
                    string temp = "";
                    for (int j = 0; j < dot; j++)
                    {
                        temp += "...";

                    }
                    listAdmin[i].Category_name = temp + " " + listAdmin[i].Category_name;
                }
            }
        }
    }
}